<template>
  <div class="postList">
    <div  v-for="(item,index) in data" :key="index">
      <div class="item" v-if="item.images.length<=2">
        <div class="image" @click="$router.push({path:'/post/detai',query:{id:item.id}})">
          <img
            v-if="!item.images[0]"
            src="http://img3.imgtn.bdimg.com/it/u=4061135862,3167765695&fm=26&gp=0.jpg"
            alt
          />
          <img v-else :src="item.images[0]" alt />
        </div>
        <div class="right">
          <a
            href="#"
            class="title"
            @click="$router.push({path:'/post/detai',query:{id:item.id}})"
          >{{item.title}}</a>
          <div
            class="content"
            @click="$router.push({path:'/post/detai',query:{id:item.id}})"
          >{{item.summary}}</div>
          <div class="bottom">
            <div class="leftText">
              <i class="el-icon-location-outline"></i>
              <span>{{item.cityName}} &nbsp;&nbsp; by</span>&nbsp;&nbsp;
              <img
                class="head"
                :src="`${$axios.defaults.baseURL}${item.account.defaultAvatar}`"
                alt
              />&nbsp;&nbsp;
              <span class="ncikname">{{item.account.nickname}}</span>&nbsp;&nbsp;
              <i class="el-icon-view"></i>&nbsp;
              <span class="readNum">{{item.watch}}</span>
            </div>
            <div class="like">
              <span class="number">{{item.like}}</span> 赞
            </div>
          </div>
        </div>
      </div>
			
			<div class="items" v-else-if="item.images.length>2">
				<a
          href="#"
          class="title"
          @click="$router.push({path:'/post/detai',query:{id:item.id}})"
        >{{item.title}}</a>

        <div
          class="content"
          @click="$router.push({path:'/post/detai',query:{id:item.id}})"
        >{{item.summary}}</div>

				<div class="images" @click="$router.push({path:'/post/detai',query:{id:item.id}})">
          <img :src="item.images[0]" alt />
          <img :src="item.images[1]" alt />
          <img :src="item.images[2]" alt />
        </div>

        <div class="bottom">
          <div class="leftText">
            <i class="el-icon-location-outline"></i>
            <span>{{item.cityName}} &nbsp;&nbsp; by</span>&nbsp;&nbsp;
            <img
              class="head"
              :src="`${$axios.defaults.baseURL}${item.account.defaultAvatar}`"
              alt
            />&nbsp;&nbsp;
            <span class="ncikname">{{item.account.nickname}}</span>&nbsp;&nbsp;
            <i class="el-icon-view"></i>&nbsp;
            <span class="readNum">{{item.watch}}</span>
          </div>
          <div class="like">
            <span class="number">{{item.like}}</span> 赞
          </div>
        </div>
			</div>
    </div>  
  </div>
</template>

<script>
export default {
  props: {
    data: {
      type: Array,
      // 默认是空数组
      default: []
    }
  }
};
</script>

<style lang="less" scoped>
.postList {
  box-sizing: border-box;
  color: #333;
  .item{
    display: flex;
    padding: 20px 0;
    border-bottom: 1px solid #eeeeee;
     .image {
      flex: 1;
      margin-right: 5px;
      img {
        width: 220px;
        height: 150px;
        object-fit: cover;
      }
    }
    .right {
      display: flex;
      justify-content: space-around;
      flex-direction: column;
      .title {
        font-size: 20px;
        font-weight: normal;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box; //将元素设为盒子伸缩模型显示
        -webkit-box-orient: vertical; //伸缩方向设为垂直方向
        -webkit-line-clamp: 1; //超出3行隐藏，并显示省略号
      }
      .content {
        font-size: 14px;
        color: #808d93;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box; //将元素设为盒子伸缩模型显示
        -webkit-box-orient: vertical; //伸缩方向设为垂直方向
        -webkit-line-clamp: 3; //超出3行隐藏，并显示省略号
      }
      .bottom {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .leftText {
          display: flex;
          align-items: center;
          font-size: 12px;
          color: #cab6aa;
          > img {
            width: 16px;
            height: 16px;
            border-radius: 50%;
          }
          .ncikname {
            color: #ffc11f;
          }
        }
        .like {
          color: #ffa500;
          font-size: 16px;
          .number {
            font-size: 14px;
          }
        }
      }
    }
	}
	.items{
		display: flex;
    justify-content: space-around;
    flex-direction: column;
    padding: 20px 0;
		border-bottom: 1px solid #eeeeee;
		.title {
			margin-top: 10px;
      font-size: 20px;
      font-weight: normal;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box; //将元素设为盒子伸缩模型显示
      -webkit-box-orient: vertical; //伸缩方向设为垂直方向
      -webkit-line-clamp: 1; //超出3行隐藏，并显示省略号
    }
    .content {
        font-size: 14px;
        color: #808d93;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box; //将元素设为盒子伸缩模型显示
        -webkit-box-orient: vertical; //伸缩方向设为垂直方向
        -webkit-line-clamp: 3; //超出3行隐藏，并显示省略号
		}
		.images{
			margin: 20px 0;
			display: flex;
			justify-content: space-around;
			img {
        width: 220px;
        height: 150px;
        object-fit: cover;
      }
		}
		.bottom {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .leftText {
          display: flex;
          align-items: center;
          font-size: 12px;
          color: #cab6aa;
          > img {
            width: 16px;
            height: 16px;
            border-radius: 50%;
          }
          .ncikname {
            color: #ffc11f;
          }
        }
        .like {
          color: #ffa500;
          font-size: 16px;
          .number {
            font-size: 14px;
          }
        }
      }
	}
}
</style>